local skel = fk.CreateSkill {
  name = "emo__nanliang",
}

Fk:loadTranslationTable{
  ["emo__nanliang"] = "难量",
  [":emo__nanliang"] = "出牌阶段对每名角色限一次，你可以令一名角色选一项：1.视为对你使用一张【决斗】；2.交给你一张牌并翻面。",

  ["#emo__nanliang"] = "选择1名角色，其须选择视为对你用【决斗】；或给你1牌并翻面",
  ["#emo__nanliang_duel"] = "视为对 %src 使用【决斗】",
  ["#emo__nanliang_give"] = "交给 %src 一张牌并翻面",
  ["#emo__nanliang-card"] = "请交给 %src 一张牌",

  ["$emo__nanliang1"] = "让我来帮你吧！",
}

skel:addEffect("active", {
  anim_type = "control",
  prompt = "#emo__nanliang",
  card_num = 0,
  target_num = 1,
  card_filter = Util.FalseFunc,
  target_filter = function (self, player, to_select, selected)
    return #selected == 0 and not table.contains(player:getTableMark("emo__nanliang-phase"), to_select.id)
  end,
  times = function (self, player)
    if player.phase ~= Player.Play then return -1 end
    return #table.filter(Fk:currentRoom().alive_players, function (p)
      return not table.contains(player:getTableMark("emo__nanliang-phase"), p.id)
    end)
  end,
  can_use = function(self, player)
    return table.find(Fk:currentRoom().alive_players, function (p)
      return not table.contains(player:getTableMark("emo__nanliang-phase"), p.id)
    end)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local to = effect.tos[1]
    room:addTableMark(player, "emo__nanliang-phase", to.id)
    local choices = {}
    local card = Fk:cloneCard("duel")
    card.skillName = skel.name
    if not to:prohibitUse(card) and not to:isProhibited(player, card) then
      table.insert(choices, "#emo__nanliang_duel:"..player.id)
    end
    if not to:isNude() then
      table.insert(choices, "#emo__nanliang_give:"..player.id)
    end
    if #choices == 0 then return end
    if room:askToChoice(to, { choices = choices, skill_name = skel.name}):startsWith("#emo__nanliang_duel") then
      room:useVirtualCard("duel", nil, to, player, skel.name, true)
    else
      if not to:isNude() and to ~= player then
        local cards = room:askToCards(to, { min_num = 1, max_num = 1, include_equip = true, skill_name = skel.name, cancelable = false,
        prompt = "#emo__nanliang-card:"..player.id})
        room:moveCardTo(cards, Player.Hand, player, fk.ReasonGive, skel.name, nil, false, to)
      end
      if not to.dead then
        to:turnOver()
      end
    end
  end,
})

skel:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "emo__nanliang-phase", 0)
end)

return skel
